<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %><%--
  Created by IntelliJ IDEA.
  User: 86185
  Date: 2020/10/24
  Time: 14:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>名单抽取</title>
</head>
<body>
    <%
        String[] array = {"莫少聪",
                "陆宣容",
                "蒙丹荔",
                "吴添昊",
                "于文霞",
                "彭石源",
                "覃荣君",
                "杨启婷",
                "赵一莲",
                "梁秀梅",
                "李烨健",
                "韦航",
                "蒙贞吉",
                "李宏盛",
                "黄键华",
                "莫瑛玮",
                "罗丽菊",
                "陆柳荣",
                "蓝宏金",
                "黄小燕",
                "卢祖镇",
                "赖俊基",
                "刘家梅",
                "韦忠锦",
                "叶鹏",
                "陈汉华",
                "陈昱伶",
                "覃泉霖",
                "金磊",
                "岑松峻",
                "陈桂民",
                "陈银银",
                "蒙林燕",
                "周刚鸿",
                "姚灿林",
                "杨勇辉",
                "吴晖",
                "陈家有",
                "谢世杰",
                "潘家盛",
                "王日圣",
                "蒋浏亭",
                "苏博湘",
                "姜家璇"
        };

        System.out.println(array.length);
        //已经抽取到的
        List<String> list = new ArrayList<>();
        int count = 0;
        int addCount = 0;
        while (list.size() < array.length) {
            //[0, array.length -1]
            int r = (int) (Math.random() * array.length);
            if (!list.contains(array[r])) {
                list.add(array[r]);
                addCount++;
            }
            count++;
        }
        System.out.println("循环了" + count + "次数");
        System.out.println("循环有效添加" + addCount + "次数");
        out.print(list);
        //在Java中集合，在遍历时，不可以改变集合的大小
//        for (String item : list) {
////            list.remove(item);
//            list.add("1");
//        }
        //支持一边遍历，一边修改集合的大小
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            iterator.next();
            iterator.remove();
        }
        System.out.println(list);
    %>
</body>
</html>
